package com.example.yml;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener , CompoundButton.OnCheckedChangeListener {
   EditText et_name,et_pass,et_repass,et_phone;
   CheckBox cb_cy,cb_hj,cb_tt;
   RadioGroup rg;
   RadioButton rb_xb1,rb_xb2;
   Button button;
   String ah,sex;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        et_name=findViewById(R.id.et_name);
        et_pass=findViewById(R.id.et_pass);
        et_repass=findViewById(R.id.et_repass);
        et_phone=findViewById(R.id.et_phone);
        cb_cy=findViewById(R.id.cb_cy);
        cb_hj=findViewById(R.id.cb_hj);
        cb_tt=findViewById(R.id.cb_tt);
        rg=findViewById(R.id.rg);
        rb_xb1=findViewById(R.id.rb_xb1);
        rb_xb2=findViewById(R.id.rb_xb2);
        button=findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                zc();

            }
        });
    }
    public void  zc(){
        String name=et_name.getText().toString();
        String pass=et_pass.getText().toString();
        String repass=et_repass.getText().toString();
        String phone=et_phone.getText().toString();
        if(TextUtils.isEmpty(name)||TextUtils.isEmpty(pass)||TextUtils.isEmpty(repass)||TextUtils.isEmpty(phone)){
            Toast.makeText(this, "输入框不能为空", Toast.LENGTH_SHORT).show();
        }else {
            if(name.length()>=5||pass.length()>=5){
                if(pass.equals(repass)){
                    if(phone.length()==11){
                        User user=new User();
                        user.setName(name);
                        user.setPass(pass);
                        Intent intent=new Intent();
                        intent.setClass(Main2Activity.this,yuanmenglong0526.class);
                        intent.putExtra("name",user);
                        setResult(0,intent);
                        finish();
                    }else {
                        Toast.makeText(this, "电话号码只能11位", Toast.LENGTH_SHORT).show();
                    }
                }else {
                    Toast.makeText(this, "两次密码不一致", Toast.LENGTH_SHORT).show();
                }

            }else {
                Toast.makeText(this, "用户名或密码不能少于五位", Toast.LENGTH_SHORT).show();
            }

        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
     switch (compoundButton.getId()){
         case R.id.cb_cy:
             if (b){
                 Toast.makeText(this, "se", Toast.LENGTH_SHORT).show();
                 ah=ah+"抽烟";
             }
             break;
         case R.id.cb_hj:
             if (b){
                 ah=ah+"喝酒";
             }
             break;
         case R.id.cb_tt:
             if (b){
                 ah=ah+"烫头";
             }
             break;

     }
    }
}
